home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI446.ASC < prev    next >
Text File  |  1992-04-16  |  4KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Turbo Pascal                           NUMBER  :  446
  9.   VERSION  :  1.0
  10.        OS  :  WIN
  11.      DATE  :  April 16, 1992                           PAGE  :  1/3
  12.  
  13.     TITLE  :  Changing Color of Buttons with Bitmaps
  14.  
  15.  
  16.  
  17.  
  18.   {$R bnn}
  19.   { The above resource assumes that you have a dialog name
  20.   'dialog_1' that contains three buttons of id 101, 102, 103.
  21.   There should also be six bitmaps in the resource of value 1101,
  22.   3101, 5101 which hold the bitmaps for the red button and 1102,
  23.   3102, 5102 which hold the bitmaps for the blue button.  Clicking
  24.   the blue button should change the third button blue and clicking
  25.   the red button should change it red.
  26.   }
  27.  
  28.   uses WinTypes, WinProcs, WObjects, bwcc;
  29.   const
  30.     id_Red    = 101;
  31.     id_Blue   = 102;
  32.     id_Change = 103;
  33.  
  34.     IsRed: Boolean = False;
  35.     IsBlue: Boolean = False;
  36.  
  37.   type
  38.     TApp = object(TApplication)
  39.       procedure InitMainWindow; virtual;
  40.     end;
  41.  
  42.     PMyDialog = ^TMyDialog;
  43.     TMyDialog = object(TDialog)
  44.       Red, Blue: array[0..2] of hBitMap;
  45.       constructor Init(AParent :PWindowsObject; AName: PChar);
  46.       destructor Done; virtual;
  47.       procedure ChangeToRed(var Message: TMessage);
  48.                            virtual id_First + id_Red;
  49.       procedure ChangeToBlue(var Message: TMessage);
  50.                            virtual id_First + id_Blue;
  51.     end;
  52.  
  53.   { TApp }
  54.   procedure TApp.InitMainWindow;
  55.   begin
  56.     MainWindow := New(PMyDialog, Init(Nil, 'dialog_1'));
  57.   end;
  58.  
  59.   { TMyDialog }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Turbo Pascal                           NUMBER  :  446
  75.   VERSION  :  1.0
  76.        OS  :  WIN
  77.      DATE  :  April 16, 1992                           PAGE  :  2/3
  78.  
  79.     TITLE  :  Changing Color of Buttons with Bitmaps
  80.  
  81.  
  82.  
  83.  
  84.   constructor TMyDialog.Init(AParent :PWindowsObject; AName:
  85.   PChar);
  86.   begin
  87.     TDialog.Init(AParent, AName);
  88.     Red[0] := LoadBitMap(hInstance, PChar(1101));
  89.     Red[1] := LoadBitMap(hInstance, PChar(3101));
  90.     Red[2] := LoadBitMap(hInstance, PChar(5101));
  91.  
  92.     Blue[0] := LoadBitMap(hInstance, PChar(1102));
  93.     Blue[1] := LoadBitMap(hInstance, PChar(3102));
  94.     Blue[2] := LoadBitMap(hInstance, PChar(5102));
  95.   end;
  96.  
  97.   destructor TMyDialog.Done;
  98.   var
  99.     I: Integer;
  100.   begin
  101.     TDialog.Done;
  102.     if Not IsRed then
  103.       for I := 0 to 2 do
  104.         DeleteObject(Red[I]);
  105.     if Not IsBlue then
  106.       for I := 0 to 2 do
  107.         DeleteObject(Blue[I]);
  108.   end;
  109.  
  110.   procedure TMyDialog.ChangeToRed(var Message: TMessage);
  111.   begin
  112.     SendDlgItemMessage(HWindow, id_Change, bbm_SetBits, 0,
  113.                        LongInt(@ Red));
  114.     InvalidateRect(GetDlgItem(HWindow, id_Change), Nil, True);
  115.     IsRed := True;
  116.     IsBlue := False;
  117.   end;
  118.  
  119.   procedure TMyDialog.ChangeToBlue(var Message: TMessage);
  120.   begin
  121.     SendDlgItemMessage(HWindow, id_Change, bbm_SetBits, 0,
  122.                        LongInt(@ Blue));
  123.     InvalidateRect(GetDlgItem(HWindow, id_Change), Nil, True);
  124.     IsRed := False;
  125.     IsBlue := True;
  126.   end;
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Turbo Pascal                           NUMBER  :  446
  141.   VERSION  :  1.0
  142.        OS  :  WIN
  143.      DATE  :  April 16, 1992                           PAGE  :  3/3
  144.  
  145.     TITLE  :  Changing Color of Buttons with Bitmaps
  146.  
  147.  
  148.  
  149.  
  150.   var
  151.     App: TApp;
  152.   begin
  153.     App.Init('Test');
  154.     App.Run;
  155.     App.Done;
  156.   end.
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.